/*
 * Copyright kecp
 * Jun 01, 2010
 */

package traveller;

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.media.Manager;
import javax.microedition.media.MediaException;
import javax.microedition.media.Player;

/**
 * 闹钟
 * @author kecp
 */
public class Alarm{

    Player player = null;


    public boolean createMedia() {
        if( player != null ){
            player.close();
        }
        InputStream inStrm = Object.class.getResourceAsStream("/res/nokiaAlarm.mid");
        if( inStrm == null )
            return false;
        
        try {
            player = Manager.createPlayer(inStrm, "audio/midi");
            player.setLoopCount(1);
        } catch (IOException ex) {
            ex.printStackTrace();
            return false;
        } catch (MediaException ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }

    public boolean play() {
        try {
    
            player.start();
        } catch (MediaException ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }

    public boolean  stop() {
        try {
            player.stop();
        } catch (MediaException ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }
    public boolean pause() {
        try {
            player.stop();
        } catch (MediaException ex) {
            ex.printStackTrace();
            return false;
        }
        return true;
    }

}